package com.zyz.I_多线程.常用方法;

/**
 * @author: vick
 * @Date: 2025/3/21
 * @Description:
 * @version: 1.0
 */
public class JoinThread {
    public static void main(String[] args) throws InterruptedException {
        //主线程
        Thread main = Thread.currentThread();

        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    if (i == 5) {
                        //强制执行
                        main.join();
                    }
                    Thread.sleep(10);
                    System.out.println(Thread.currentThread().getName() + "===》" + i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"渣男").start();

        //主线程
        for (int i = 0; i < 10; i++) {
            Thread.sleep(10);
            System.out.println("曹贼====》" + i);
        }
    }
}
